import CryptoJS from 'crypto-js'

export function AESdecrypt(word, secret) {
  const base = CryptoJS.MD5(secret).toString()
  const secretKey = CryptoJS.enc.Utf8.parse(base)
  return CryptoJS.enc.Utf8.stringify(
    CryptoJS.AES.decrypt(word, secretKey, { mode: CryptoJS.mode.ECB, padding: CryptoJS.pad.Pkcs7 })
  ).toString()
}

export function AESencrypt(word, secret) {
  const base = CryptoJS.MD5(secret).toString()
  const secretKey = CryptoJS.enc.Utf8.parse(base)
  const srcs = CryptoJS.enc.Utf8.parse(word)
  return CryptoJS.AES.encrypt(srcs, secretKey, { mode: CryptoJS.mode.ECB, padding: CryptoJS.pad.Pkcs7 }).toString()
}
